package Text1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86184
 * Date: 2023-02-14
 * Time: 13:16
 */
class Animal1{
    public String name;
    public int age;
    public Animal1(String name,int age){
        this.name=name;
        this.age=age;
    }

    public void eat(){
        System.out.println(name+"正在吃饭");
    }
}

class Dog1 extends Animal1{
    public Dog1(String name,int age){
        super(name,age);
    }

    //重写
    @Override
    public void eat(){
        System.out.println(name+"正在吃狗粮");
    }
}

class Cat1 extends Animal1{
    public Cat1(){
        super("元宝",10);
    }

    public Cat1(String name,int age){
        super(name,age);
    }

    public void barks(){
        System.out.println(name+"正在抓老鼠");
    }
    @Override
    public void eat(){
        System.out.println(name+"正在吃猫粮");
    }
}
public class DownTransformation {
    public static void main(String[] args) {
        Animal1 animal1=new Cat1();
        Animal1 animal2=new Dog1("小七",5);
        Cat1 cat=(Cat1)animal1;  //向下转型
        cat.barks();

        /*
        Cat1 cat1=(Cat1)animal2;  //如果animal2创建了一个Dog的实例就会报错
        cat1.barks();
        */
    }
}
